import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由el-breadcrumb在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
 noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
 title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
 icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
 breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
 activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
 }dispose/incidentHandle
 */
let prefix = ''
if (window.__POWERED_BY_QIANKUN__ && window.parentType == 'hash') {
  prefix = '/zxxdapp' // /zjgapp为主应用的activeRule
  window.prefix = '/zxxdapp'
}
// 公共路由
export const constantRoutes = [
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true,
  },
  {
    path: '*',
    component: () => import('@/views/error/404'),
    hidden: true,
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true,
  },

  {
    path: prefix + '/',
    redirect: '/specialProject/assets/assetLibrary',
  },

  /** =============================行政监管路由======================= */
  {
    path: prefix + '/specialProject',
    redirect: prefix + '/specialProject/smItem',
    component: () => import('@/views/index'),
    children: [
      {
        path: 'unit',
        component: () => import('@/views/specialProject/unit/index.vue'),
        name: 'sp_unit',
        meta: { title: '运维单位', keepAlive: false },
      },
      {
        path: 'unitDetail',
        component: () => import('@/views/specialProject/unit/components/detail.vue'),
        name: 'sp_unit_detail',
        meta: { keepAlive: false },
      },
      {
        path: 'personnel',
        component: () => import('@/views/specialProject/personnel/index.vue'),
        name: 'sp_personnel',
        meta: { title: '运维人员', keepAlive: false },
      },
      {
        path: 'personnelDetail',
        component: () => import('@/views/specialProject/personnel/components/detail.vue'),
        name: 'sp_personnel_detail',
        meta: { keepAlive: false },
      },
      {
        path: 'smItem',
        component: () => import('@/views/specialProject/smItem/index.vue'),
        name: 'sp_smItem',
        meta: { title: 'SM项目', keepAlive: false },
      },
      {
        path: 'smItemDetail',
        component: () => import('@/views/specialProject/smItem/components/detail.vue'),
        name: 'sp_sm_detail',
        meta: { keepAlive: false },
      },
      {
        path: 'post',
        component: () => import('@/views/specialProject/post/inde.vue'),
        name: 'sp_post',
        meta: { title: '运维岗位', keepAlive: false },
      },
      {
        path: 'autoNumber',
        component: () => import('@/views/specialProject/autoNumber/index.vue'),
        name: 'sp_auto-number',
        meta: { title: '自动编号', keepAlive: false },
      },
      {
        path: 'periodicity',
        component: () => import('@/views/specialProject/periodicity/index.vue'),
        name: 'sp_periodicity',
        meta: { title: '周期性任务', keepAlive: false },
      },
      {
        path: 'periodicityDetail',
        component: () => import('@/views/specialProject/periodicity/components/details.vue'),
        name: 'sp_periodicity-detail',
        meta: { keepAlive: false },
      },
      {
        path: 'scheduling',
        component: () => import('@/views/specialProject/scheduling/index.vue'),
        name: 'sp_scheduling',
        meta: { title: '排班管理', keepAlive: false },
      },
      {
        path: 'schedulingDetail',
        component: () => import('@/views/specialProject/scheduling/components/detail.vue'),
        name: 'sp_scheduling-detail',
        meta: { keepAlive: false },
      },
      {
        path: 'zczp',
        name: 'zczp',
        component: () => import('@/views/index'),
        meta: { title: '自查自评', keepAlive: false },
        children: [
          {
            path: 'templateManage',
            component: () => import('@/views/specialProject/templateManage/index.vue'),
            name: 'assetsComparison',
            meta: { title: '模板管理', keepAlive: false },
          },
          {
            path: 'templatePreview',
            component: () => import('@/views/specialProject/templateManage/preview.vue'),
            name: 'templatePreview',
            meta: { title: '预览', keepAlive: false },
          },
          {
            path: 'safetyReportManagement',
            component: () => import('@/views/specialProject/safetyReportManagement/index.vue'),
            name: 'safetyReportManagement',
            meta: { title: '报告管理', keepAlive: false },
          },
          {
            path: 'reportPreview',
            component: () => import('@/views/specialProject/safetyReportManagement/preview.vue'),
            name: 'reportPreview',
            meta: { title: '预览', keepAlive: false },
          },
        ],
      },
      {
        path: 'assets',
        name: 'assets',
        component: () => import('@/views/index'),
        meta: { title: '资产管理', keepAlive: false },
        children: [
          {
            path: 'assetView',
            component: () => import('@/views/specialProject/assetView/index.vue'),
            name: 'sp_asset-view',
            meta: { title: '资产概览', keepAlive: false },
          },
          {
            path: 'assetLibrary',
            component: () => import('@/views/specialProject/asset/index.vue'),
            name: 'sp_asset',
            meta: { title: '资产库管理', keepAlive: false },
          },
          {
            path: 'assetLibraryDetail',
            component: () => import('@/views/specialProject/asset/components/detail.vue'),
            name: 'sp_asset-detail',
            meta: { keepAlive: false },
          },
          {
            path: 'scrap',
            component: () => import('@/views/specialProject/scrap/index.vue'),
            name: 'sp_scrap',
            meta: { title: '已报废资产', keepAlive: false },
          },
          {
            path: 'dict',
            component: () => import('@/views/specialProject/dict/index.vue'),
            name: 'sp_dict',
            meta: { title: '字典管理', keepAlive: false },
          },
          {
            path: 'assetRecords',
            component: () => import('@/views/specialProject/assetRecords/index.vue'),
            name: 'sp_asset-records',
            meta: { title: '资产变更记录', keepAlive: false },
          },
          {
            path: 'Inventory',
            component: () => import('@/views/specialProject/Inventory/index.vue'),
            name: 'sp_Inventory',
            meta: { title: '资产盘点任务', keepAlive: false },
          },
          {
            path: 'InventoryResult',
            component: () => import('@/views/specialProject/Inventory/components/result.vue'),
            name: 'sp_Inventory-result',
            meta: {keepAlive: false },
          },
          {
            path: 'InventoryDetail',
            component: () => import('@/views/specialProject/Inventory/components/details.vue'),
            name: 'sp_Inventory-detail',
            meta: { keepAlive: false },
          },
        ],
      },

      {
        path: 'bmTrain',
        component: () => import('@/views/specialProject/bmTrain/inde.vue'),
        name: 'sp_bm_train',
        meta: { title: 'BM培训', keepAlive: false },
      },
      {
        path: 'entryExit',
        component: () => import('@/views/specialProject/entryExit/inde.vue'),
        name: 'sp_entry_exit',
        meta: { title: '出入境申请记录', keepAlive: false },
      },
      {
        path: 'heartTalk',
        component: () => import('@/views/specialProject/heartTalk/inde.vue'),
        name: 'sp_heart_talk',
        meta: { title: '谈心谈话记录', keepAlive: false },
      },
      {
        path: 'userConfig',
        component: () => import('@/views/specialProject/systemUser/index.vue'),
        name: 'sp_system_user',
        meta: { title: '系统用户管理', keepAlive: false },
      },
      {
        path: 'userDetail',
        component: () => import('@/views/specialProject/systemUser/components/detail.vue'),
        name: 'sp_user_detail',
        meta: { keepAlive: false },
      },
      {
        path: 'workOrder',
        component: () => import('@/views/specialProject/workOrder/index.vue'),
        name: 'sp_work_order',
        meta: { title: '工单列表', keepAlive: false },
      },
      {
        path: 'workBench',
        component: () => import('@/views/specialProject/workBench/index.vue'),
        name: 'sp_work_bench',
        meta: { title: '工作台', keepAlive: false },
      },
      {
        path: 'warningConfig',
        component: () => import('@/views/specialProject/warningConfig/index.vue'),
        name: 'warning_config',
        meta: { title: '提醒设置', keepAlive: false },
      },
    ],
  },
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = []

// 防止连续点击多次路由报错
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}
// 宝兰德的是哈希模式，打包部署自己的服务器的时候是history模式
const isUM = window.versionType == 'webgate'
export default new Router({
  base: window.__POWERED_BY_QIANKUN__ ? '/zxxdapp/' : '/zxxdapp/',
  mode: isUM ? 'hash' : 'history',
  routes: constantRoutes,
})
